const http = require('http')
const { createProxyMiddleware } = require('http-proxy-middleware')
const server = http.createServer((req, rep) => {
    let url = req.url
    rep.writeHead(200, {
        'Access-Control-Allow-Origin': '*',
        "Content-Type": 'application/json;charset=utf-8'
    })
    if (/^\/api/.test(url)) {
        const proxy = createProxyMiddleware('/api',
            {
                target: 'https://e.juejin.cn/resources/book',
                changeOrigin: true,
                pathRewrite: {
                    '^/api': ''
                }
            }
        )
        proxy(req, rep)

    }
    rep.end()
})
server.listen(8088)